/*     */ package com.wgcloud.service;
/*     */ 
/*     */ import com.alibaba.excel.EasyExcel;
/*     */ import com.wgcloud.dto.AppExcelChartDto;
/*     */ import com.wgcloud.dto.DbTableExcelChartDto;
/*     */ import com.wgcloud.dto.DockerExcelChartDto;
/*     */ import com.wgcloud.dto.ExcelChartDto;
/*     */ import com.wgcloud.dto.FileWarnStateExcelDto;
/*     */ import com.wgcloud.entity.AppState;
/*     */ import com.wgcloud.entity.CpuState;
/*     */ import com.wgcloud.entity.DbTableCount;
/*     */ import com.wgcloud.entity.DockerState;
/*     */ import com.wgcloud.entity.FileWarnInfo;
/*     */ import com.wgcloud.entity.FileWarnState;
/*     */ import com.wgcloud.entity.MemState;
/*     */ import com.wgcloud.entity.NetIoState;
/*     */ import com.wgcloud.entity.SysLoadState;
/*     */ import com.wgcloud.service.AppStateService;
/*     */ import com.wgcloud.service.CpuStateService;
/*     */ import com.wgcloud.service.DbTableCountService;
/*     */ import com.wgcloud.service.DockerStateService;
/*     */ import com.wgcloud.service.FileWarnStateService;
/*     */ import com.wgcloud.service.MemStateService;
/*     */ import com.wgcloud.service.NetIoStateService;
/*     */ import com.wgcloud.service.SysLoadStateService;
/*     */ import com.wgcloud.util.DateUtil;
/*     */ import java.io.IOException;
/*     */ import java.io.OutputStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletOutputStream;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.eclipse.jetty.util.StringUtil;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Service;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Service
/*     */ public class ExcelExportService
/*     */ {
/*     */   @Autowired
/*     */   CpuStateService cpuStateService;
/*     */   @Autowired
/*     */   MemStateService memStateService;
/*     */   @Autowired
/*     */   NetIoStateService netIoStateService;
/*     */   @Autowired
/*     */   SysLoadStateService sysLoadStateService;
/*     */   
/*     */   public void exportExcel(Map<String, Object> params, HttpServletResponse response) {
/*  56 */     ServletOutputStream out = null;
/*     */     try {
/*  58 */       List<String> datetimeList = new ArrayList<>();
/*  59 */       List<CpuState> cpuStateList = this.cpuStateService.selectAllByParams(params);
/*  60 */       Map<String, CpuState> cpuStateMap = new HashMap<>();
/*  61 */       for (CpuState cpuState : cpuStateList) {
/*  62 */         datetimeList.add(cpuState.getDateStr());
/*  63 */         cpuStateMap.put(cpuState.getDateStr(), cpuState);
/*     */       } 
/*  65 */       List<MemState> memStateList = this.memStateService.selectAllByParams(params);
/*  66 */       Map<String, MemState> memStateMap = new HashMap<>();
/*  67 */       for (MemState memState : memStateList) {
/*  68 */         memStateMap.put(memState.getDateStr(), memState);
/*     */       }
/*  70 */       List<SysLoadState> ysLoadSstateList = this.sysLoadStateService.selectAllByParams(params);
/*  71 */       Map<String, SysLoadState> ysLoadSstateMap = new HashMap<>();
/*  72 */       for (SysLoadState sysLoadState : ysLoadSstateList) {
/*  73 */         ysLoadSstateMap.put(sysLoadState.getDateStr(), sysLoadState);
/*     */       }
/*  75 */       List<NetIoState> netIoStateList = this.netIoStateService.selectAllByParams(params);
/*  76 */       Map<String, NetIoState> netIoStateMap = new HashMap<>();
/*  77 */       for (NetIoState netIoState : netIoStateList) {
/*  78 */         netIoStateMap.put(netIoState.getDateStr(), netIoState);
/*     */       }
/*  80 */       List<ExcelChartDto> excelChartList = new ArrayList<>();
/*  81 */       for (String datetimeStr : datetimeList) {
/*  82 */         ExcelChartDto dto = new ExcelChartDto();
/*  83 */         dto.setDatetime(datetimeStr);
/*  84 */         if (null != cpuStateMap.get(datetimeStr)) {
/*  85 */           dto.setCpuPer(((CpuState)cpuStateMap.get(datetimeStr)).getSys());
/*     */         }
/*  87 */         if (null != memStateMap.get(datetimeStr)) {
/*  88 */           dto.setMemPer(((MemState)memStateMap.get(datetimeStr)).getUsePer());
/*     */         }
/*  90 */         if (null != netIoStateMap.get(datetimeStr)) {
/*  91 */           dto.setDropin(((NetIoState)netIoStateMap.get(datetimeStr)).getDropin());
/*  92 */           dto.setDropout(((NetIoState)netIoStateMap.get(datetimeStr)).getDropout());
/*  93 */           dto.setRxbyt(((NetIoState)netIoStateMap.get(datetimeStr)).getRxbyt());
/*  94 */           dto.setTxbyt(((NetIoState)netIoStateMap.get(datetimeStr)).getTxbyt());
/*  95 */           dto.setRxpck(((NetIoState)netIoStateMap.get(datetimeStr)).getRxpck());
/*  96 */           dto.setTxpck(((NetIoState)netIoStateMap.get(datetimeStr)).getTxpck());
/*     */         } 
/*  98 */         if (null != ysLoadSstateMap.get(datetimeStr)) {
/*  99 */           dto.setOneLoad(((SysLoadState)ysLoadSstateMap.get(datetimeStr)).getOneLoad());
/* 100 */           dto.setFiveLoad(((SysLoadState)ysLoadSstateMap.get(datetimeStr)).getFiveLoad());
/* 101 */           dto.setFifteenLoad(((SysLoadState)ysLoadSstateMap.get(datetimeStr)).getFifteenLoad());
/*     */         } 
/* 103 */         excelChartList.add(dto);
/*     */       } 
/* 105 */       String hostname = params.get("hostname").toString();
/* 106 */       String startTime = params.get("startTime").toString();
/* 107 */       String endTime = params.get("endTime").toString();
/* 108 */       String fileName = hostname + "_" + startTime + "_" + endTime;
/* 109 */       response.setContentType("application/vnd.ms-exce");
/* 110 */       response.setCharacterEncoding("utf-8");
/* 111 */       response.addHeader("Content-Disposition", "filename=" + fileName + ".xlsx");
/* 112 */       EasyExcel.write((OutputStream)response.getOutputStream(), ExcelChartDto.class).sheet("sheet").doWrite(excelChartList);
/* 113 */     } catch (Exception e) {
/* 114 */       e.printStackTrace();
/*     */     } finally {
/*     */       
/*     */       try {
/* 118 */         if (out != null) {
/* 119 */           out.close();
/*     */         }
/* 121 */       } catch (IOException e) {
/* 122 */         e.printStackTrace();
/*     */       } 
/*     */     } 
/*     */   }
/*     */   @Autowired
/*     */   AppStateService appStateService; @Autowired
/*     */   DbTableCountService dbTableCountService; @Autowired
/*     */   DockerStateService dockerStateService;
/*     */   @Autowired
/*     */   FileWarnStateService fileWarnStateService;
/*     */   
/*     */   public void exportAppExcel(Map<String, Object> params, HttpServletResponse response) {
/* 134 */     ServletOutputStream out = null;
/*     */     try {
/* 136 */       List<AppState> appStateList = this.appStateService.selectAllByParams(params);
/* 137 */       List<AppExcelChartDto> excelChartList = new ArrayList<>();
/* 138 */       for (AppState appState : appStateList) {
/* 139 */         AppExcelChartDto appExcelChartDto = new AppExcelChartDto();
/* 140 */         appExcelChartDto.setDatetime(appState.getDateStr());
/* 141 */         appExcelChartDto.setCpuPer(appState.getCpuPer());
/* 142 */         appExcelChartDto.setMemPer(appState.getMemPer());
/* 143 */         excelChartList.add(appExcelChartDto);
/*     */       } 
/* 145 */       String startTime = params.get("startTime").toString();
/* 146 */       String endTime = params.get("endTime").toString();
/* 147 */       String fileName = startTime + "_" + endTime + "_appState";
/* 148 */       response.setContentType("application/vnd.ms-exce");
/* 149 */       response.setCharacterEncoding("utf-8");
/* 150 */       response.addHeader("Content-Disposition", "filename=" + fileName + ".xlsx");
/* 151 */       EasyExcel.write((OutputStream)response.getOutputStream(), AppExcelChartDto.class).sheet("sheet").doWrite(excelChartList);
/* 152 */     } catch (Exception e) {
/* 153 */       e.printStackTrace();
/*     */     } finally {
/*     */       
/*     */       try {
/* 157 */         if (out != null) {
/* 158 */           out.close();
/*     */         }
/* 160 */       } catch (IOException e) {
/* 161 */         e.printStackTrace();
/*     */       } 
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void exportDockerExcel(Map<String, Object> params, HttpServletResponse response) {
/* 173 */     ServletOutputStream out = null;
/*     */     try {
/* 175 */       List<DockerState> dockerStateList = this.dockerStateService.selectAllByParams(params);
/* 176 */       List<DockerExcelChartDto> excelChartList = new ArrayList<>();
/* 177 */       for (DockerState dockerState : dockerStateList) {
/* 178 */         DockerExcelChartDto dockerExcelChartDto = new DockerExcelChartDto();
/* 179 */         dockerExcelChartDto.setDatetime(dockerState.getDateStr());
/* 180 */         dockerExcelChartDto.setMemPer(dockerState.getMemPer());
/* 181 */         excelChartList.add(dockerExcelChartDto);
/*     */       } 
/* 183 */       String startTime = params.get("startTime").toString();
/* 184 */       String endTime = params.get("endTime").toString();
/* 185 */       String fileName = startTime + "_" + endTime + "_dockerState";
/* 186 */       response.setContentType("application/vnd.ms-exce");
/* 187 */       response.setCharacterEncoding("utf-8");
/* 188 */       response.addHeader("Content-Disposition", "filename=" + fileName + ".xlsx");
/* 189 */       EasyExcel.write((OutputStream)response.getOutputStream(), DockerExcelChartDto.class).sheet("sheet").doWrite(excelChartList);
/* 190 */     } catch (Exception e) {
/* 191 */       e.printStackTrace();
/*     */     } finally {
/*     */       
/*     */       try {
/* 195 */         if (out != null) {
/* 196 */           out.close();
/*     */         }
/* 198 */       } catch (IOException e) {
/* 199 */         e.printStackTrace();
/*     */       } 
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void exportDbTableExcel(Map<String, Object> params, HttpServletResponse response) {
/* 211 */     ServletOutputStream out = null;
/*     */     try {
/* 213 */       List<DbTableCount> dbTableCountList = this.dbTableCountService.selectAllByParams(params);
/* 214 */       List<DbTableExcelChartDto> excelChartList = new ArrayList<>();
/* 215 */       for (DbTableCount dbTableCount : dbTableCountList) {
/* 216 */         DbTableExcelChartDto dbTableExcelChartDto = new DbTableExcelChartDto();
/* 217 */         if (null != dbTableCount.getCreateTime()) {
/* 218 */           dbTableExcelChartDto.setDatetime(DateUtil.getDateTimeString(dbTableCount.getCreateTime()));
/*     */         }
/* 220 */         dbTableExcelChartDto.setTableCount(dbTableCount.getTableCount());
/* 221 */         excelChartList.add(dbTableExcelChartDto);
/*     */       } 
/* 223 */       String fileName = StringUtil.valueOf(params.get("dbTableId")) + "_dbTableCount";
/* 224 */       response.setContentType("application/vnd.ms-exce");
/* 225 */       response.setCharacterEncoding("utf-8");
/* 226 */       response.addHeader("Content-Disposition", "filename=" + fileName + ".xlsx");
/* 227 */       EasyExcel.write((OutputStream)response.getOutputStream(), DbTableExcelChartDto.class).sheet("sheet").doWrite(excelChartList);
/* 228 */     } catch (Exception e) {
/* 229 */       e.printStackTrace();
/*     */     } finally {
/*     */       
/*     */       try {
/* 233 */         if (out != null) {
/* 234 */           out.close();
/*     */         }
/* 236 */       } catch (IOException e) {
/* 237 */         e.printStackTrace();
/*     */       } 
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void exportFileWarnStateExcel(FileWarnInfo fileWarnInfo, Map<String, Object> params, HttpServletResponse response) {
/* 249 */     ServletOutputStream out = null;
/*     */     try {
/* 251 */       List<FileWarnState> fileWarnStateList = this.fileWarnStateService.selectAllByParams(params);
/* 252 */       List<FileWarnStateExcelDto> excelChartList = new ArrayList<>();
/* 253 */       for (FileWarnState fileWarnState : fileWarnStateList) {
/* 254 */         FileWarnStateExcelDto fileWarnStateExcelDto = new FileWarnStateExcelDto();
/* 255 */         if (null != fileWarnState.getCreateTime()) {
/* 256 */           fileWarnStateExcelDto.setDatetime(DateUtil.getDateTimeString(fileWarnState.getCreateTime()));
/*     */         }
/* 258 */         fileWarnStateExcelDto.setWarContent(fileWarnState.getWarContent());
/* 259 */         excelChartList.add(fileWarnStateExcelDto);
/*     */       } 
/* 261 */       String fileName = fileWarnInfo.getHostname() + "_fileWarnInfo";
/* 262 */       response.setContentType("application/vnd.ms-exce");
/* 263 */       response.setCharacterEncoding("utf-8");
/* 264 */       response.addHeader("Content-Disposition", "filename=" + fileName + ".xlsx");
/* 265 */       EasyExcel.write((OutputStream)response.getOutputStream(), FileWarnStateExcelDto.class).sheet("sheet").doWrite(excelChartList);
/* 266 */     } catch (Exception e) {
/* 267 */       e.printStackTrace();
/*     */     } finally {
/*     */       
/*     */       try {
/* 271 */         if (out != null) {
/* 272 */           out.close();
/*     */         }
/* 274 */       } catch (IOException e) {
/* 275 */         e.printStackTrace();
/*     */       } 
/*     */     } 
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/service/ExcelExportService.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */